home *** CD-ROM | disk | FTP | other *** search
- Path: fido.asd.sgi.com!news
- From: Emmanuel Mogenet <mgix@aw.sgi.com>
- Newsgroups: comp.lang.c++
- Subject: Re: C++ Shortcomings ?
- Date: Fri, 15 Mar 1996 01:48:10 -0800
- Organization: Alias Wavefront
- Message-ID: <31493CDA.41C6@aw.sgi.com>
- References: <31488E8D.167E@aw.sgi.com> <4iaqch$moh@B1FF.mindspring.com>
- NNTP-Posting-Host: fddi-sgigate.sgi.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (X11; I; IRIX 5.3 IP22)
-
- Justin Rudd wrote:
- >
- > Emmanuel Mogenet <mgix@aw.sgi.com> wrote:
- >
- > >In other word, make portions of the interface to a class private to
- > >only some classes.
- >
- > > 1. Wouldn't that be nicer than the friend mechanism that cracks
- > > open a class a spill its guts ?
- > > 2. Is there a clean way to achieve in today's C++ standard ?
- > > 3. Or is it a bad idea altogether ?
- >
- > I'm not sure what you mean by this...You want to have a function
- > SomeMethodOnlyCallableByManagerForClassA(); That can be called like
- > this:
- >
- > ManagerForClassA manage;
- > manage.SomeMethodOnlyCallableByManagerForClassA();
- >
- > hm...OH WAIT...I get it....
- >
- > even though ManagerForClassA has no idea what it has inside it should
- > still be able to call a member function of A.
- >
- > Well this could be simulate using inheritance. Hm...I've never really
- > thought about this...let me get back to you on this one.
-
- No.
-
- I guess my post was messy and unclear.
- What I want is to be able for a class A to tell:
-
-
- class A
- {
- restricted B:
- void DoSomething();
- }
-
- This means: Ok, the method A::DoSomething is public, but not
- public for everybody. Only members of class B can have access to
- this method.
-
- It's a bit like the friend operator, but instead of spilling
- everything to the friend, we just let him peep through a specialized window.
-
- >
- > >2. Pointer type manipulation
- > >-----------------------------
- >
- > >A very disappointing thing in C++ (unless I am mistaken and it is actually
- > >possible to do so) is the following situation:
- >
- > >If A is a class, then most operations on A can be redefined.
- > >Because A is a full blown type.
- >
- > >Sadly, the same can not be said about A* (type: pointer to A).
- >
- > >Even though A* is a type, none of its default manipulations
- > >can be redefined.
- >
- > >Example: You can tell C++, that you want to gain control of the
- > >situation whenever an object of type A is duplicated.
- >
- > >You do so by redefining the default copy constructor and the default
- > >assignment operator.
- >
- > >But can you tell C++ that you want to gain control whenever a pointer of
- > >A* is duplicated ? Why can't I redefine the copy constructor for the type A* ?
- >
- > >In my way of looking at thing, that'd be a *great* way of doing clean reference
- > >counting, instead of half-baked method using a redefinition of operator->.
- >
- > >Comments ?
- >
- > Ok...so you are saying you can do something like this...
-
- 8< ... snip snip ... 8<
-
- No.
-
- What I meant was: I would like to be able to redefine the default
- copy constructor for pointers.
-
- In other words, when I write:
- class A
- {
- };
-
- main()
- {
- A *a;
- B *b;
-
- a=new A();
- b=a;
- }
-
- I want the compiler to trap this for me and give me control.
- What I really want the compiler to do is:
-
- main()
- {
- 1. Call the constructor of object A* (that's what we do. We build an A*)
- 2. Call the constructor of object B*
-
- Call the constructor for object A* (to temporarily store the result of new)
- Call the assignment method (to assign the result of new to a)
- Call the assignment operator (to assign the value of a to b)
-
- }
-
- Another way to put it:
- I would like to be able to write
-
- class A*
- {
- A*(); // To build a pointer to A
- A*(const A*&) // To build an A* from another A*
- ~A*(); // To get hold of what happens when a pointer to A goes out of scope
-
- A* operator=(const A*&); // To redefine assignment
-
- }
-
-
- All this complicated mechanics would allow to build
- industrial-strength reference counting on objects.
-
- - Mgix
-